//
//  Extension.swift
//  Status
//
//  Created by 花轮 on 15/5/23.
//  Copyright (c) 2015年 花轮. All rights reserved.
//

import UIKit
extension UIImage {
    func scaleImg(#width: CGFloat) -> UIImage {
        let size = scaleImageWithSize(width)
        
        UIGraphicsBeginImageContext(size)
        
        drawInRect(CGRect(origin: CGPointZero, size: size))
        
        let img = UIGraphicsGetImageFromCurrentImageContext()
        
        UIGraphicsEndImageContext()
        
        return img
    }
    
    private func scaleImageWithSize(width: CGFloat) -> CGSize {
        let scale = size.width / width
        let h = size.height / scale
        return CGSizeMake(width, h)
    }
}
